package fmanganiello.tests.javatests.depinj.billing.real;

import com.google.inject.Inject;

import fmanganiello.tests.javatests.depinj.billing.BillingService;
import fmanganiello.tests.javatests.depinj.billing.ChargeResult;
import fmanganiello.tests.javatests.depinj.billing.PizzaOrder;
import fmanganiello.tests.javatests.depinj.billing.Receipt;
import fmanganiello.tests.javatests.depinj.creditcard.CreditCard;
import fmanganiello.tests.javatests.depinj.creditcard.CreditCardProcessor;

public class RealBillingService implements BillingService {
	private final CreditCardProcessor processor;
	
	@Inject
	public RealBillingService(final CreditCardProcessor processor) {
		this.processor = processor;
	}
	
	public Receipt chargeOrder(PizzaOrder order, CreditCard creditCard) {
		ChargeResult result = processor.charge(creditCard, order.getAmount());
		return result.wasSuccessful() ?
				Receipt.forSuccessfulCharge(order.getAmount()) : 
				Receipt.forDeclinedCharge(result.getDeclineMessage());
	}
}
